﻿using System;
using System.Collections.Generic;

namespace FallingRox
{
    public class Collider
    {
        public void CalculateCollisions(List<Rock> objects, ICollidable obj)
        {
            for (int i = 0; i < objects.Count; i++)
            {
                if (objects[i].CanCollideWith(obj.GetObjectType()))
                {
                    //to match the actual collision
                    List<MatrixCoords> rock = objects[i].GetImageCoordinatesMatrix();
                    List<MatrixCoords> rocket = obj.GetImageCoordinatesMatrix();
                    for (int k = 0; k < rock.Count; k++)
                    {
                        bool collided = false;
                        for (int l = 0; l < rocket.Count; l++)
                        {
                            if (rock[k] == rocket[l])
                            {
                                objects[i].RespondToCollision();
                                obj.RespondToCollision();
                                collided = true;
                                break;
                            }
                        }
                        if (collided)
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
}
